
// 存放接口
import request from '@/utils/request.js'
import store from '../store'

// 封装接口请求的方法
export const allChannelListApi = () => {
  return request({
    url: '/v1_0/channels'
  })
}

// 用户登录
export const loginApi = ({ mobile, code }) => {
  return request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: {
      mobile,
      code
    }
  })
}

// 用户文章频道列表
export const userChannelApi = () => request({
  url: '/v1_0/user/channels',
  header: {
    Authorization: 'Bearer ' + store.state.token
  }
})

// 获取文章新闻推荐
export const articlesListAPI = ({ channelId, timestamp }) => {
  return request({
    url: '/v1_0/articles',
    method: 'GET',
    params: {
      channel_id: channelId,
      // 兼容性写法 保证当前面的timestamp 没有值的时候会取到后面的时间戳
      // 防止请求参数缺少 接口报错
      timestamp: timestamp || (new Date()).getTime()

    }
  })
}

// 对文章不喜欢

export const articleDislikeAPI = ({ target }) => {
  return request({
    url: '/v1_0/article/dislikes',
    method: 'POST',
    data: {
      target: target
    }
    // headers: {
    //   Authorization: 'Bearer ' + store.state.token
    // }
  })
}

// 举报垃圾内容
export const articleReportsAPI = ({ target, type, remark }) => {
  return request({
    url: '/v1_0/article/reports',
    method: 'POST',
    data: {
      target, type, remark
    }
    // headers: {
    //   Authorization: 'Bearer ' + store.state.token
    // }
  })
}

// 更新频道接口
export const updateChannelAPI = ({ channels }) => {
  return request({
    url: '/v1_0/user/channels',
    method: 'PUT',
    data: {
      channels: channels
    }
  })
}

// 1
export const suggestListAPI = ({ q }) => {
  return request({
    url: '/v1_0/suggestion',
    params: {
      q: q
    }
  })
}

// 搜索结果

// 搜索 - 结果列表
export const searchResultListAPI = ({ q, page = 1 }) => {
  return request({
    url: '/v1_0/search',
    params: {
      q,
      page
    }
  })
}
